﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;

namespace BroRPG.GameComponents
{
    public enum BlocType
    {
        Air = 0,
        Grass = 1,
        Dirt = 2
    }

    public class Chunck
    {
        public static  int CHUNCK_SIZE_X = 20;
        public static  int CHUNCK_SIZE_Y = 20;
        public static  int CHUNCK_SIZE_Z = 3;

        public static  int CHUNCK_WIDTH = CHUNCK_SIZE_X * 40;
        public static  int CHUNCK_HEIGHT = CHUNCK_SIZE_Y * 40;

        //bloc de 20 de large
        //        15 de haut
        //        3 etages
        private int[,,] blocs;
        private int[,] light;
        public int X;
        public int Y;

        public Chunck(int posx, int posy,int type)
        {
            blocs = new int[CHUNCK_SIZE_X, CHUNCK_SIZE_Y, CHUNCK_SIZE_Z];
            light = new int[CHUNCK_SIZE_X, CHUNCK_SIZE_Y];

            X = posx;
            Y = posy;

            for (int y = 0; y < CHUNCK_SIZE_Y; y++)
            {
                for (int x = 0; x < CHUNCK_SIZE_X; x++)
                {
                    blocs[x, y, 0] = type;
                }
            }
        }

        public Chunck(int posx, int posy)
        {
            blocs = new int[CHUNCK_SIZE_X, CHUNCK_SIZE_Y, CHUNCK_SIZE_Z];
            light = new int[CHUNCK_SIZE_X, CHUNCK_SIZE_Y];

            X = posx;
            Y = posy;

            for (int y = 0; y < CHUNCK_SIZE_Y; y++)
            {
                for (int x = 0; x < CHUNCK_SIZE_X; x++)
                {
                    blocs[x, y, 0] = Helpers.RandomHelper.rnd.Next(1,3);
                }
            }
        }



        public List<Tuile> Render(int x, int y)
        {
            List<Tuile> retour = new List<Tuile>();
            for (int z = 0; z < CHUNCK_SIZE_Z; z++)
            {
                BlocType type = (BlocType)blocs[x, y, z];

                Tuile tile = new Tuile("world", type.ToString(), z);
                tile.MaterialColor = Color.White;
                tile.Position = new Vector2(X * CHUNCK_SIZE_X * 40 + x * 40 + 20, Y * CHUNCK_SIZE_Y * 40 + y * 40 + 20);
                retour.Add(tile);
            }                
            return retour;
        }
    }
}
